<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<!-- <cl-add-btn /> -->
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 条件搜索 -->
			<cl-search ref="Search" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table">

				<!-- 自定义列 -->
				<template #column-idCardFrontImg="{ scope }">
					<el-image :src="scope.row.idCardFrontImg" style="width: 200px;" />
				</template>

				<template #column-idCardBackImg="{ scope }">
					<el-image :src="scope.row.idCardBackImg" style="width: 200px;" />
				</template>

				<template #column-businessLicenseImg="{ scope }">
					<el-image :src="scope.row.businessLicenseImg" style="width: 200px;" />
				</template>

			</cl-table>
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
defineOptions({
	name: "user-agent",
});

import { useCrud, useTable, useUpsert, useSearch } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { useI18n } from "vue-i18n";
import { useDict } from '/$/dict';








const { service } = useCool();
const { t } = useI18n();

const { dict } = useDict();


// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: t("审核状态"),
			prop: "auditStatus",
			component: { name: "el-select", options: dict.get('auditStatus'), },
			span: 24,
		},
		{
			label: t("拒接原因"),
			prop: "rejectReason",
			component: {
				name: "el-input", props: {
					clearable: true, maxlength: 20,


					// 多行文本
					type: 'textarea',
				}
			},
			span: 24,
			hidden: ({ scope }) => {
				console.log('scopescopescope', scope);

				// 如果审核状态是拒接才显示
				return scope.auditStatus != "2";
			}
		},
		{
			label: t("分成比例"),
			prop: "splitRatio",
			component: { name: "el-input", props: { clearable: true, type: "number", min: 0, max: 100 } },
			span: 24,
		},
	],
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		// { label: t("用户名"), prop: "username", minWidth: 120 },
		{ label: t("手机号"), prop: "phone", minWidth: 120 },
		{ label: t("身份证正面图片"), prop: "idCardFrontImg", minWidth: 220 },
		{ label: t("身份证反面图片"), prop: "idCardBackImg", minWidth: 220 },
		{ label: t("营业执照图片"), prop: "businessLicenseImg", minWidth: 220 },
		{ label: t("身份证号码"), prop: "idCardNo", minWidth: 120 },
		{
			label: t("加盟形式"), prop: "joinType", minWidth: 120, formatter: (row, column) => {
				return row.joinType === 1 ? '个人' : '企业'
			}
		},
		{
			label: t("审核状态"), prop: "auditStatus", minWidth: 120, formatter: (row, column) => {
				// 审核状态, 0待审核，1审核通过，2审核未通过
				return row.auditStatus == 0 ? '待审核' : row.auditStatus == 1 ? '审核通过' : '审核未通过'
			}
		},
		{ label: t("拒接原因"), prop: "rejectReason", minWidth: 120 },
		{ label: t("分成比例"), prop: "splitRatio", minWidth: 120 },
		{
			label: t("创建时间"),
			prop: "createTime",
			minWidth: 170,
			sortable: "desc",
			component: { name: "cl-date-text" },
		},

		{ type: "op", buttons: ["edit", "delete"] },
	],
});

// cl-search
const Search = useSearch();

// cl-crud
const Crud = useCrud(
	{
		service: service.user.agent,
	},
	(app) => {
		app.refresh();
	},
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
